﻿using Contract.Infrastructure.Repository;
using Contract.WebApi.Application.Commands;
using MediatR;

namespace Contract.WebApi.Application.CommandHandler
{
    public class SaveHZContractCommandHandler : IRequestHandler<SaveHZContractCommands, int>
    {
        private readonly IRepository<Domain.Contract> repository;

        public SaveHZContractCommandHandler(IRepository<Domain.Contract> repository)
        {
            this.repository = repository;
        }

        public async Task<int> Handle(SaveHZContractCommands request, CancellationToken cancellationToken)
        {
            DateTime now = DateTime.Now;
            string serialNumber = now.ToString("yyyyMMddHHmmss");
            request.ContractNumber = "HZ" + serialNumber;
            request.ContractType = 1;
            request.AuditState = 0;
            var inf = await repository.AddAsync(request);

            return inf;
        }
    }
}
